package top.healthylife.gateway.platform.eye.dto.BaseRes;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import top.healthylife.gateway.dto.request.result.ApiResultDto;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author GaoZexi
 * @datetime 2020/7/8 10:29
 */
@Data
@Accessors(chain = true)
@ApiModel("天眼查返回对象封装基类")
public class EyeResBaseResultDto<T> extends ApiResultDto {

    @ApiModelProperty(value = "总数")
    Integer total;

    @ApiModelProperty(value = "结果集",hidden = true)
    List<T> items;
    @ApiModelProperty(value= "页大小")
    int pageSize;
    @ApiModelProperty(value= "页码数")
    int pageNum;
    @ApiModelProperty(value = "结果集与items一样,为适配天眼查接口返回，请不要通过GET获取此属性")
    List<T> result;

    public void setResult(List<T> result) {
        this.items = result;
        this.result = result;
    }

    /**
     * 重写查询结果
     *
     * @author maoxiaomeng
     * @date: 2020/7/9 14:37
     * @return: java.util.List<T>
     */
    public List<T> getResult() {
        return Optional.ofNullable(this.items).map(ArrayList::new).orElseGet(ArrayList::new);
    }


}
